package com.example.springboot.Service;

import com.example.springboot.entity.Course;
import com.example.springboot.entity.Course_sort;
import com.example.springboot.mapper.Course_selectMapper;
import com.example.springboot.mapper.Course_sortMapper;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class CourseSave {

    @Autowired
    private Course_sortMapper mapper;
    @Autowired
    private Course_selectMapper course_selectMapper;

    public String getTime(Integer course_id) {
        List<Course_sort> time = mapper.courseTime(course_id);
        String msg = "";
        for (int i = 0; i < time.size(); i++) {
            msg = msg + time.get(i).get_time(time.get(i).getCourse_time());
        }
        return msg;
    }


    public String getConflict(Integer course_id, Integer stuID) {
        List<Course_sort> time = mapper.courseTime(course_id);  //  查到课程的上课时间

        for (int i = 0; i < time.size(); i++) {
            if (course_selectMapper.finndCourse(stuID,time.get(i).getCourse_time()).size() == 0){
                continue;
            }else{
                return "不可选";
            }
        }
        return "可选";
//        学生的选课
    }


    public  HashMap<String,String> schedle(List<Course> courses) {
        HashMap<String,String> res = new HashMap();
        courses.forEach(course -> {
            res.put("ss"+course.getCourse_time(),course.getCourse_name()+course.getRoom_id()+"号楼");
        });
        return res;



    }
}
